package com.du.demo.exception;

import com.du.demo.utils.BaseResult;
import  org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


@ControllerAdvice("com.du.demo.controller")
public class GlobalException {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public BaseResult error(Exception e){
        e.printStackTrace();
        return BaseResult.error("500", "系统内部错误");

    }
    @ExceptionHandler(CustomException.class)
    @ResponseBody
    public BaseResult customError(CustomException e){
        e.printStackTrace();

        return  BaseResult.error(e.getCode(),e.getMsg());
    }

}
